/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       default_heroes.h

	$Header: /game/default_heroes.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef DEFAULT_HEROES_H_INCLUDED
#define DEFAULT_HEROES_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning( disable: 4786 ) // Disable the ever so helpful "identifier was truncated to '255' characters" warning

#include <cassert>
#include <string>
#include <vector>

#include "bool_array.h"

enum t_hero_class;

struct t_default_hero
{
	std::string  biography;
	int          biography_id;
	t_hero_class hero_class;
	bool         is_male;
	std::string  name;
	int          portrait_id; // use get_hero_portrait to get image
};

class t_default_hero_list
{
public:
	t_default_hero_list();

	void                        clear();
	void                        discard( int biography_id, int portrait_id ); // use biography_id, not portrait_id
	t_bool_array const & 		get_allowed_portrait_list() const;
	t_default_hero              get_generic( int portrait_id ) const;
	bool                        is_portrait_used( int portrait_id ) const;
	bool                        read( std::streambuf& buffer );
	void						set_allowed_portrait_list( t_bool_array const & allowed_portraits );
	void                        use( int biography_id, int portrait_id );
	bool                        write( std::streambuf& buffer ) const;

	std::vector<t_default_hero> get_unused( t_hero_class hero_class, bool male ) const;
protected:
	std::vector<int> m_portrait_count;
	std::vector<int> m_biography_count;
	t_bool_array     m_allowed_portraits; // If m_allowed_portraits[portrait_id] is false, never return that portrait_id.
									      // Note: OK to be smaller than maximum portrait id
};

inline void t_default_hero_list::clear()
{
	memset( &(*m_portrait_count.begin()), 0, m_portrait_count.size() * sizeof(int) );
	memset( &(*m_biography_count.begin()), 0, m_biography_count.size() * sizeof(int) );
}

inline void t_default_hero_list::discard( int biography_id, int portrait_id )
{
	m_portrait_count[portrait_id]--;
	m_biography_count[biography_id]--;
}

inline t_bool_array const & t_default_hero_list::get_allowed_portrait_list() const
{
	return m_allowed_portraits;
}

inline bool t_default_hero_list::is_portrait_used( int portrait_id ) const
{
	assert( portrait_id >= 0 && portrait_id < (int)m_portrait_count.size() );
	return m_portrait_count[ portrait_id ] > 0;
}

inline void t_default_hero_list::set_allowed_portrait_list( t_bool_array const & allowed_portraits )
{
	m_allowed_portraits = allowed_portraits;
}

inline void t_default_hero_list::use( int biography_id, int portrait_id )
{
	m_portrait_count[portrait_id]++;
	m_biography_count[biography_id]++;
}

std::string		get_default_biography( int biography_id );
int				get_default_biography_id_from_portrait_id( int portrait_id );
t_default_hero	get_default_hero( int biography_id );
t_hero_class	get_default_hero_class( int biography_id );
bool			get_default_is_male( int biography_id );
std::string		get_default_name( int biography_id );
int				get_default_portrait_id( int biography_id );
bool			hero_allowed_by_default( int portrait_id );

#endif // DEFAULT_HEROES_H_INCLUDED
